package com.navi168.fwq21.hyzl;

import com.navi168.fwq21.R;
import com.navi168.fwq21.db.Sqlh;
import com.navi168.fwq21.hyzl.mod.Favo;
import com.navi168.fwq21.hyzl.mod.MypoiItems;
import com.navi168.fwq21.util.Tools;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class PoiMenu extends Activity {
	private Button back;
	private Button driver;
	private Button sendadd;
	private Button addpoi;
	private TextView address;
	private MypoiItems poiItems;
	private Bundle bundle;
	private Favo favo;
	private Sqlh sqlh;
	private Context mcontext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.poiitem);
		mcontext = this.getApplicationContext();
		sqlh = sqlh.getInstance(mcontext);
		bundle = PoiMenu.this.getIntent().getBundleExtra("poi_xf");
		poiItems = (MypoiItems) bundle.getParcelable("poi_xf");

		findviews();
		setlisters();
	}

	private void setlisters() {
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				PoiMenu.this.finish();

			}
		});

		driver.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(PoiMenu.this,Drive.class);
				intent.putExtra("fromname", poiItems.getTitle());
				startActivity(intent);
			}
		});

		sendadd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(PoiMenu.this, SendList.class);
				intent.putExtra("poi_xf", bundle);
				startActivity(intent);

			}
		});

		addpoi.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				addToFav();
				PoiMenu.this.finish();
			}
		});

	}

	private void findviews() {
		back = (Button) findViewById(R.id.returnmap);
		driver = (Button) findViewById(R.id.drive);
		sendadd = (Button) findViewById(R.id.sendadd);
		addpoi = (Button) findViewById(R.id.addpoi);
		address = (TextView) findViewById(R.id.adrrestext);
		address.setText(poiItems.getTitle());
	}

	private void addToFav() {
		favo = new Favo();
		favo.setFav_lat(poiItems.getLatit());
		favo.setFav_lon(poiItems.getLongit());
		favo.setFav_snipeet(poiItems.getSnippet());
		favo.setFav_title(poiItems.getTitle());
		favo.setJoin_date(new Tools().getnowtime());
		int noti = sqlh.add(favo);
		Log.i("mylog", "noti" + noti);
	}

}
